define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'user/userquyu/index' + location.search,
                    // add_url: 'user/userquyu/add',
                    // edit_url: 'user/userquyu/edit',
                    // del_url: 'user/userquyu/del',
                    // multi_url: 'user/userquyu/multi',
                    // import_url: 'user/userquyu/import',
                    table: 'user_copy1',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        // {field: 'a_performance_text', title: __('A区总业绩'), operate: false},
                        // {field: 'b_performance_text', title: __('B区总业绩'), operate: false},
                        {field: 'area', title: __('Area'), searchList: {"A":__('A'),"B":__('B')}, formatter: Table.api.formatter.normal},
                        {field: 'mobile', title: __('Mobile'), operate: 'LIKE'},
                        {field: 'nickname', title: __('Nickname'), operate: 'LIKE'},
                        {field: 'username', title: __('Username'), operate: 'LIKE'},
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table, events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate,
                            buttons: [
                                {
                                    title: __('查询下级'),
                                    text: '查询下级',
                                    // classname: 'btn btn-xs btn-warning btn-addtabs',
                                    classname: 'btn btn-xs btn-success btn-dialog',
                                    icon: 'fa fa-rmb',
                                    url: 'user/Userquyu/index?parent_user_id={id}',
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        // if(Config.quanxian.ids==8){
                                        //     return false;
                                        // }else{
                                        //     return true;
                                        // }
                                        return true;
                                    },
                                },
                            ]
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
